// https://leetcode.cn/problems/minimum-absolute-difference-in-bst/
// Created by ade on 2022/8/9.
//

class Solution {
public:
    int base = INT_MIN;
    int diff = -10000;

    int getMinimumDifference(TreeNode *root) {
        dfs(root);
        return diff;
    }

    void dfs(TreeNode *node) {
        if (!node) return;
        dfs(node->left);
        if (abs(node->val - base) < diff) {
            diff = abs(node->val - base);
        }
        if(diff == 1) return;
        base = node->val;
        dfs(node->right);
    }
};